package com.ruoyi.edu.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.edu.domain.EduPolicy;
import com.ruoyi.edu.service.IEduPolicyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 教育政策Controller
 * 
 * @author ruoyi
 * @date 2024-06-29
 */
@RestController
@RequestMapping("/edu/policy")
public class EduPolicyController extends BaseController
{
    @Autowired
    private IEduPolicyService eduPolicyService;

    /**
     * 查询教育政策列表
     */
    @PreAuthorize("@ss.hasPermi('edu:policy:list')")
    @GetMapping("/list")
    public TableDataInfo list(EduPolicy eduPolicy)
    {
        startPage();
        List<EduPolicy> list = eduPolicyService.selectEduPolicyList(eduPolicy);
        return getDataTable(list);
    }

    /**
     * 导出教育政策列表
     */
    @PreAuthorize("@ss.hasPermi('edu:policy:export')")
    @Log(title = "教育政策", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EduPolicy eduPolicy)
    {
        List<EduPolicy> list = eduPolicyService.selectEduPolicyList(eduPolicy);
        ExcelUtil<EduPolicy> util = new ExcelUtil<EduPolicy>(EduPolicy.class);
        util.exportExcel(response, list, "教育政策数据");
    }

    /**
     * 获取教育政策详细信息
     */
    @PreAuthorize("@ss.hasPermi('edu:policy:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(eduPolicyService.selectEduPolicyById(id));
    }

    /**
     * 新增教育政策
     */
    @PreAuthorize("@ss.hasPermi('edu:policy:add')")
    @Log(title = "教育政策", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EduPolicy eduPolicy)
    {
        return toAjax(eduPolicyService.insertEduPolicy(eduPolicy));
    }

    /**
     * 修改教育政策
     */
    @PreAuthorize("@ss.hasPermi('edu:policy:edit')")
    @Log(title = "教育政策", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EduPolicy eduPolicy)
    {
        return toAjax(eduPolicyService.updateEduPolicy(eduPolicy));
    }

    /**
     * 删除教育政策
     */
    @PreAuthorize("@ss.hasPermi('edu:policy:remove')")
    @Log(title = "教育政策", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(eduPolicyService.deleteEduPolicyByIds(ids));
    }
}
